<template>
  <div class="search-history">
    <van-cell  title="搜索历史">
      <div class="option" v-if="isDeleteShow">
        <!-- props如果是对象类型，可以修改，如果是重新赋值修改，会报错，建议交给都父组件修改，或者自己用data或者计算属性初始化 -->
        <span @click="$emit('update-histories',[])">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow=false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow=true"></van-icon>
    </van-cell>
    <van-cell  :title="histroy" v-for="(histroy,index) in searchHistoryList" :key="index" @click="onDelete(histroy,index)">
      <van-icon name="close" v-show="isDeleteShow" />
    </van-cell>
  </div>
</template>
<script>
export default {
  name: 'SearchHistory',
  props: {
    searchHistoryList: {
      type: Array,
      require: true
    }
  },
  data () {
    return {
      isDeleteShow: false
    }
  },
  created () {

  },
  methods: {
    onDelete (histroy, index) {
      if (this.isDeleteShow) {
        this.searchHistoryList.splice(index)
      } else {
        // 非删除状态下
        this.$emit('search', histroy)
      }
    }
  }
}
</script>
<style lang="less" scoped>

</style>
